package org.Exception;

public class TestException {
    public static void testFinally() {
        try {
            Integer.parseInt("abc");
        } catch (Exception e) {
            System.out.println("catched");
            throw new RuntimeException(e);
        } finally {
            System.out.println("finally");
        }
    }

    public static void testFinallyException() {
        try {
            Integer.parseInt("abc");
        } catch (Exception e) {
            System.out.println("catched");
            throw new RuntimeException(e);
        } finally {
            System.out.println("finally");
            throw new IllegalArgumentException();
        }
    }

    static class Person {
        String[] name = new String[2];
        Address address = new Address();
    }

    static class Address {
        String city;
        String street;
        String zipcode;
    }

    public static void testNullPointerException() {
        Person p = new Person();
        try {
            System.out.println(p.address.city.toLowerCase());
        } catch (NullPointerException e) {
            System.out.println("Catch NullPointerException");
        } finally {
            System.out.println("testNullPointerException");
        }

    }
}
